package com.example.controller;

import com.example.pojo.Dept;

import com.example.pojo.Result;
import com.example.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {


    @Autowired
    public DeptService deptService;

    // 查询全部数据

    @GetMapping
    public Result list(){
        log.info("查询所有部门");
        List<Dept> list = deptService.list();
        return new Result().success(list);
    }

    @DeleteMapping("/{id}")
    public Result delectbyid(@PathVariable Integer id){
        deptService.delect(id);
        return new Result().success();
    }
    @PostMapping
    public Result insert(@RequestBody Dept dept){
        deptService.insert(dept);
        return new Result().success();
    }

    //修改部门
    @PutMapping
    public Result updat(@RequestBody Dept dept){
        log.info("修改部门");
        deptService.updata(dept);

        return Result.success();
    }
}
